<!DOCTYPE html>
<html>

	<head>
		<meta charset="UTF-8">
		<title>签到</title>
		<meta name="viewport"
			content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
		<link href="../../css/mui.min.css" rel="stylesheet" />
		<link rel="stylesheet" href="../css/allApp.css" />
		<link rel="stylesheet" href="css/css.css" />
		<style type="text/css">
			body,.mui-content{
				background-color: #ffffff!important;
			}
			.qd {
				display: none;
				width: 85%;
				height: 44px;
				line-height: 44px;
				text-align: center;
				border-radius: 6px;
				background-color: #EDF3FF;
				border:1px solid  #0077DC;
				color: #004A86;
				margin-top: 50px;
			}
			.back {
				display: block;
				width: 85%;
				height: 44px;
				line-height: 44px;
				text-align: center;
				border-radius: 6px;
				background-color: #EDF3FF;
				border:1px solid  #0077DC;
				color: #004A86;
				margin-top: 50px;
			}
			
			.box{
				padding:10px 20px;
			}
			.box span{
				padding:0px 20px 0 0;
				display: inline-block;
			}
		</style>
	</head>

	<body>
		<header class="mui-bar mui-bar-nav">
			<a class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left"></a>
			<h1 class="mui-title">签到人数</h1>
		</header>
		<div class="mui-content" id="contentt" style="display: flex;align-items: center;flex-direction: column;">
			<div style="color:#125CB7;margin: 30px 0px;">签到二维码</div>
			<div style="width: 100%;text-align: center;"><img src="" style="width: 50%;height:auto;" id="qdimg">
			</div>
			
			<div style="width: 80%;margin-top: 20px;display: flex;align-items: center;">
				<img src="2.png" style="width: 30px;height: 25px;">
				<div style="color: #125CB7;">
					班组人员签名  共{{list.length}}人
				</div>
			</div>
			<div style="width: 80%;" class="box">
				<span v-for="ie in list">
					{{ie.createUser}}
				</span>
			</div>
			<div class="qd">签到</div>
			<div class="back" style="margin-top:10px;">返回</div>
		</div>
		<script src="../../js/mui.min.js"></script>
		<script src="../../js/vue.js" type="text/javascript" charset="utf-8"></script>
		<script src="../../js/jquery-3.1.1.js"></script>
		<script type="text/javascript" src="../../js/mkeyplus.base.xunjian.js"></script>
		<script src="http://api.map.baidu.com/api?v=3.0&ak=feLaTL1YEljWzFRGQNs98eUWbN6jPqmv"></script>
		<script>
			mui.init()
		
			window.vm = new Vue({
				el: "#contentt",
				data: {
					list:[]
				},
				methods: {
					
				}
			
			});
		
			var scancode;
			let popupShow = false;
			let form = {
				fillReason: '',
				classMettingId: '',
				signPlace: ''
			}
			let data = null;
			let success = null;
			let message = null;
			let u = localStorage.getItem('personal');
			let id = '';
			let stationName = '';
			u = JSON.parse(u);
			mui.plusReady(function() {
				self = plus.webview.currentWebview();
				scancode = self.scan;
				console.log('scancode=' + scancode);
				opener = self.opener()
				opener.close('none');
				getDetail()
			});

			function getDetail() {
				mui.baseApp.httpRequst1('/classmetting/j/queryClassMettingInfo', {
					id: scancode
				}, function(res) {
					data = res.data;
					if (res.success) {
						getLocation()
						id = data.id;
						stationName = data.stationName;
						form.classMettingId = id;
						form.signPlace = stationName;
						if (id) {
							getSign();
						}
						document.getElementById('qdimg').src = 'data:image/png;base64,' + data.qrCode
					} else {
						mui.toast(res.message);
					}
				}, function() {
					plus.nativeUI.closeWaiting();
				}, 'POST');
			}

			document.querySelector('.qd').addEventListener('tap', function() {
				submit();
			})
			
			document.querySelector('.back').addEventListener('tap',function () {
			    mui.back();
			})

			function getSign() {
				mui.baseApp.httpRequst1('/classmetting/j/queryClassmettingSign', {
					classMettingId: id
				}, function(res) {
					if (res.success) {
						let data = res.data;
						let list = data.signer.concat(data.retroactiveer);
						vm.list = list;
						let hasSign = list.filter(item => item.createId == u.code)

						if (hasSign.length == 0) {
							document.querySelector('.qd').style.display = 'block'
						} else {
							document.querySelector('.qd').style.display = 'none'
						}
					}
				}, function() {
					plus.nativeUI.closeWaiting();
				}, 'POST');
			}

			function submit() {
				/** 判断是签到还是补签
				 * @method submit
				 * @param{空} 
				 * @return {空} 
				 */
				let status = data.status ? parseInt(data.status) : 0
				if (status == 0) {
					sign()
				} else {
					popupShow = true
					var btnArray = ['取消', '提交'];
					mui.prompt('补签理由', '', ' ', btnArray, function(e) {
						if (e.index == 1) {
							form.fillReason = e.value;
							sign();
						} else {
							
						}
					})
				}
			}
			
			function sign() {
				/** 进行签到
				 * @method sign
				 * @param {空} 
				 * @return {空} 
				 */
				if (data && id) {
					let fn = () => {
						plus.nativeUI.showWaiting('正在签到，请稍后')
						mui.baseApp.httpRequst1('/classmetting/j/classmettingSign', {
							fillReason: form.fillReason,
							classMettingId: form.classMettingId,
							signPlace: form.signPlace
						}, function(res) {
							if (res.success) {
								mui.toast(res.message)
								getSign()
							}
							popupShow = false
							plus.nativeUI.closeWaiting();
					 }, function() {
							plus.nativeUI.closeWaiting();
						}, 'POST');
					}
					var btnArray = ['确定', '取消'];
					//已审核
					if (data.status == 2 && popupShow) {
						//已审核状态的补签
						mui.confirm('该条班会已通过审核，补签后需要重新进行审核。', '提示', btnArray, function(e) {
							if (e.index == 0) {
								fn()
					 	} else {

							}
						});
					} else {
						fn()
					}
				}
			}

			function getLocation() {
				
				// plus.geolocation.getCurrentPosition(function(p){
				// 	var coser = new BMap.Geocoder();
				//     coser.getLocation(new BMap.Point(p.coords.longitude,p.coords.latitude),function(result){
				// 		console.log('result.address======='+JSON.stringify(result));
				// 		var address = result.address;
				// 		form.signPlace = address;
				//     })
				// }, function ( e ) {
					
				// },{enableHighAccuracy:true,provider:'baidu'});
				
				plus.geolocation.getCurrentPosition(function(p) {
					let address = p.addresses;
					if(address){
						form.signPlace = address
					}else{
						var point = new plus.maps.Point(p.coords.longitude, p.coords.latitude);
						plus.maps.Map.reverseGeocode(
							point, {coordType:'bd09ll'},
							function(event) {
								var address = event.address; // 转换后的地理位置
								form.signPlace = address
							},
							function(e) {}
						);
					}
				}, function(e) {
					mui.toast(e.message);
				}, {
					geocode: true,provider:'baidu'
				});
			}
		</script>
	</body>

</html>
